/** **************************************************
 * Description: 
 * Copyright:   Copyright (c) 2008
 * Company:    cl
 * @author     caoxl
 * @version    1.0
 * @see
 HISTORY
 *  2008-7-1 caoxl Create File
 ************************************************* */
package com.bfsuolframework.core.service;

import java.util.List;

import com.bfsuolframework.core.controller.support.Pagination;
import com.bfsuolframework.core.controller.support.QueryParam;
import com.bfsuolframework.core.dao.support.HqlParameter;
import com.bfsuolframework.core.entity.Entity;

public interface Service<E extends Entity> {

	public Long save(E obj);
	
	public void update(E obj);
	
	public Long saveOrUpdate(E obj);
	
	public void merge(E obj);

	public void delete(E obj);
	
	public void delete(Long id);
	
	public void evict(E obj);

	public void clear();
	
	public int getCount(QueryParam qs);
	
	public E getById(Long ID);
	
	public List<E> findAll();
	
	public List<E> findAll(QueryParam qs);

	public List<E> findAll(QueryParam qs, int startRecord, int pageSize);

	public Pagination getPage(QueryParam qs, Pagination page);


	public Pagination getPage(String hql, HqlParameter parameters, Pagination page);

	/**
	 * 是否可以删除
	 * @param id 实例Id
	 * @return 如果验证通过，则返回null，否则返回验证错误信息
	 */
	public boolean isDeletable(Long id);
	
	/**
	 * 判断属性有无相同的值，用作新建
	 * @param propertyName 属性名称
	 * @param value 判断的值
	 * @return
	 */
	public boolean isPropertyUnique(final String propertyName, final Object value);
	/**
	 * 判断属性有无相同的值，用作更新
	 * @param propertyName 属性名称
	 * @param value 判断的值
	 * @param excludePrimaryKey 排除的主键
	 * @return
	 */
	public boolean isPropertyUnique(final String propertyName, final Object value, final Long excludePrimaryKey);
}